import { IRequestOption } from '@jl/common/composable';
import { request } from '@jl/common/utils';
import { IEmail, IResetPwdByEmailParams, IResetPwdBySessionKeyParams, ISessionKey } from './types';

/**
 * 根据邮箱获取验证码
 * @param requestOption
 * @returns
 */
export const getVerifyCodeByEmail = (
  requestOption: IRequestOption<IEmail, any>
): Promise<ISessionKey> => {
  return request({
    url: '/auth/api/forgotPwd/getVerifyCodeByEmail',
    method: 'POST',
    ...requestOption,
  });
};
/**
 * 根据邮箱验证码重置密码
 * @param requestOption
 * @returns
 */
export const resetPwdByEmail = (
  requestOption: IRequestOption<IResetPwdByEmailParams, any>
): Promise<void> => {
  return request({
    url: '/auth/api/forgotPwd/resetPwdByEmail',
    method: 'POST',
    ...requestOption,
  });
};

/**
 * 获取重置密码sessionKey
 * @returns
 */
export const getSessionKey = (): Promise<ISessionKey> => {
  return request({
    url: '/auth/api/resetPwd/getSessionKey',
    method: 'POST',
  });
};

/**
 * 依据会话标识重置密码
 * @param requestOption
 * @returns
 */
export const resetPwdBySessionKey = (
  requestOption: IRequestOption<IResetPwdBySessionKeyParams, any>
): Promise<void> => {
  return request({
    url: '/auth/api/resetPwd/resetPwdBySessionKey',
    method: 'POST',
    ...requestOption,
  });
};

/**
 * 登录获取验证码
 */
export const getAppBaseConfigByAppId = (requestOption: IRequestOption<any, any>): Promise<void> => {
  return request({
    url: `/auth/api/appBaseConfig/getAppBaseConfigByAppId?appId=${requestOption.appId}`,
    method: 'POST',
  });
};
